package cn.jhz.learn.blog.common.bean;

import com.google.common.collect.Multimap;
import lombok.*;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Optional;

@Getter
@Setter
@RequiredArgsConstructor
public class TreeNode<T> {
    private final T bean;
    private final Integer id;
    private final String level;
    private final Short seq;
    private Optional<List<TreeNode<T>>> childNodeList = Optional.empty();
    private Optional<Multimap<String, TreeNode<T>>> levelMap = Optional.empty();

    public static <T> TreeNode<T> adapt(T bean, Integer id,String level, Short seq){
        TreeNode<T> node = new TreeNode<T>(bean, id, level, seq);
        BeanUtils.copyProperties(bean, node.getBean());
        return node;
    }
}
